<?php
class Solution {
    /**
     * @param Integer[] $nums
     * @param Integer $target
     * @return Integer[]
     */
    function twoSum($nums, $target) {
        sort($nums);

        $left = 0;
        $right = count($nums) - 1;

        while ($left < $right) {
            if (($nums[$left] + $nums[$right]) > $target) {
                $right--;
                continue;
            }

            if (($nums[$left] + $nums[$right]) < $target) {
                $left++;
                continue;
            }

            return array($nums[$left], $nums[$right]);
        }

        return array(-1, -1);
    }
}